import 'package:nyh_motorcade_app/entity/main_menu_entity.dart';

mainMenuEntityFromJson(MainMenuEntity data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'].toString();
	}
	if (json['parentId'] != null) {
		data.parentId = json['parentId'].toString();
	}
	if (json['createTime'] != null) {
		data.createTime = json['createTime'].toString();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['title'] != null) {
		data.title = json['title'].toString();
	}
	if (json['level'] != null) {
		data.level = json['level'] is String
				? int.tryParse(json['level'])
				: json['level'].toInt();
	}
	if (json['sort'] != null) {
		data.sort = json['sort'] is String
				? int.tryParse(json['sort'])
				: json['sort'].toInt();
	}
	if (json['icon'] != null) {
		data.icon = json['icon'].toString();
	}
	if (json['description'] != null) {
		data.description = json['description'].toString();
	}
	if (json['status'] != null) {
		data.status = json['status'] is String
				? int.tryParse(json['status'])
				: json['status'].toInt();
	}
	if (json['children'] != null) {
		data.children = (json['children'] as List).map((v) => v).toList().cast<dynamic>();
	}
	if (json['childButton'] != null) {
		data.childButton = (json['childButton'] as List).map((v) => MainMenuChildButton().fromJson(v)).toList();
	}
	return data;
}

Map<String, dynamic> mainMenuEntityToJson(MainMenuEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['parentId'] = entity.parentId;
	data['createTime'] = entity.createTime;
	data['name'] = entity.name;
	data['title'] = entity.title;
	data['level'] = entity.level;
	data['sort'] = entity.sort;
	data['icon'] = entity.icon;
	data['description'] = entity.description;
	data['status'] = entity.status;
	data['children'] = entity.children;
	data['childButton'] =  entity.childButton?.map((v) => v.toJson())?.toList();
	return data;
}

mainMenuChildButtonFromJson(MainMenuChildButton data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'].toString();
	}
	if (json['menuId'] != null) {
		data.menuId = json['menuId'].toString();
	}
	if (json['createTime'] != null) {
		data.createTime = json['createTime'].toString();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['title'] != null) {
		data.title = json['title'].toString();
	}
	if (json['power'] != null) {
		data.power = json['power'].toString();
	}
	if (json['description'] != null) {
		data.description = json['description'].toString();
	}
	if (json['sort'] != null) {
		data.sort = json['sort'] is String
				? int.tryParse(json['sort'])
				: json['sort'].toInt();
	}
	if (json['status'] != null) {
		data.status = json['status'] is String
				? int.tryParse(json['status'])
				: json['status'].toInt();
	}
	return data;
}

Map<String, dynamic> mainMenuChildButtonToJson(MainMenuChildButton entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['menuId'] = entity.menuId;
	data['createTime'] = entity.createTime;
	data['name'] = entity.name;
	data['title'] = entity.title;
	data['power'] = entity.power;
	data['description'] = entity.description;
	data['sort'] = entity.sort;
	data['status'] = entity.status;
	return data;
}